var fileManager={
	listFile:function(){
		ajax.list({
			url : "fileManagerAction_listAllFile.action",
			dialog:'fileManagerSearchList',
			template:'fileManagerSearchListTemp',
			data:'fileManagerSearchList',
			target : "fileManagerSearchList .list",
			callback :fileManager.fileActie
		});
	},
	fileActie:function(result){
		var option=$( "#fileManagerSearchList .option");
		if(option.is('span')){
			option.removeClass('option')
			 .button({
					text: false,
					icons: {
						primary: "ui-icon-triangle-1-s"
					}
			}).bind('click', function(e) {
                e.stopPropagation();
            }).click(fileManager.displayMenu);
		}
		
		$('#fileManagerSearchList .list li').mouseover(function(){
			$(this).css('border-color','#abc123');
		}).mouseout(function(){
			$(this).css('border-color','#ffffff');
		}).dblclick(function () { 
			if($(this).hasClass('dir')){
				var root=$("#fileManagerSearchList input[name='root']");
				var value=root.val()+$($(this).children('div')[0]).attr('title')+"/";
				root.val(value);
				fileManager.listFile();
			}
		});
		if(result.data.paste){
			$('#fileManagerSearchList .menu li.paste').addClass('ui-selected');
		}else{
			$('#fileManagerSearchList .menu li.paste').removeClass('ui-selected');
		}
		$('#fileManagerSearchList .menu li').mouseover(function(){
			if($(this).hasClass('ui-selected')){
				$(this).addClass('ui-state-hover');
			}
		}).mouseout(function(){
			if($(this).hasClass('ui-selected')){
				$(this).removeClass('ui-state-hover');
			}
		});
		fileManager.checkboxChe();
	},
	parentFile:function(){
		var root=$("#fileManagerSearchList input[name='root']");
		var value=root.val()+'..'+"/";
		root.val(value);
		fileManager.listFile();
	},
	checkboxChe:function(){
		if($("#fileManagerSearchList input[name='selects']:checked").length>0){
			$('#fileManagerSearchList .menu li.cut').addClass('ui-selected');
			$('#fileManagerSearchList .menu li.copy').addClass('ui-selected');
			$('#fileManagerSearchList .menu li.delete').addClass('ui-selected');
		}else{
			$('#fileManagerSearchList .menu li.cut').removeClass('ui-selected');
			$('#fileManagerSearchList .menu li.copy').removeClass('ui-selected');
			$('#fileManagerSearchList .menu li.delete').removeClass('ui-selected');
		}
	},
	displayMenu:function(){
		$('#fileManagerSearchList .menu ul').show('fast');
		$(document).one("click", function(){
			fileManager.hidden();
		});
	},
	hidden:function(){
		$('#fileManagerSearchList .menu ul').hide('fast');
	},
	cut:function(li){
		$(li).removeClass('ui-state-hover');
		if(!$(li).hasClass('ui-selected')){
			return ;
		}
		$.post("fileManagerAction_cut.action",$("#fileManagerSearchList").serialize(),function(data){
			$('#fileManagerSearchList .menu li.paste').addClass('ui-selected');
		});
	},
	copy:function(li){
		$(li).removeClass('ui-state-hover');
		if(!$(li).hasClass('ui-selected')){
			return ;
		}
		$.post("fileManagerAction_copy.action",$("#fileManagerSearchList").serialize(),function(data){
			$('#fileManagerSearchList .menu li.paste').addClass('ui-selected');
		});
	},
	paste:function(li){
		$(li).removeClass('ui-state-hover');
		if(!$(li).hasClass('ui-selected')){
			return ;
		}
		$.post("fileManagerAction_paste.action",$("#fileManagerSearchList").serialize(),function(data){
			if($.isEmptyObject(data.actionErrors)){
				fileManager.listFile();
			}else{
				alert(data.actionErrors.join('\n'));
			}
			$('#fileManagerSearchList .menu li.paste').removeClass('ui-selected');
		});
	},
	del:function(li){
		$(li).removeClass('ui-state-hover');
		if(!$(li).hasClass('ui-selected')){
			return ;
		}
		if(confirm('\u60a8\u786e\u5b9a\u8981\u5220\u9664\uff1f')) {
			$.post("fileManagerAction_delete.action",$("#fileManagerSearchList").serialize(),function(data){
				fileManager.listFile();
			});
		}
	},
	uploadFile:function(){
		var process=$('#fileUploadProcess');
		if(!process.is('form')){
			var dia=['fileUploadProcess'];
			dialog.loadDep(dia,{},fileManager.uploadFile);
			return;
		}
		$("#fileUpload [name='root']").val($("#fileManagerSearchList [name='root']").val());
		$('#fileUpload').ajaxSubmit({
			url:"fileManagerAction_uploadFile.action",
		    beforeSend: function() {
		    	process.dialog('open');
		    	process.children(".percent").progressbar({
					value: 0
				});
		    },
		    uploadProgress: function(event, position, total, percentComplete) {
		    	process.children(".percent").progressbar({
					value: percentComplete
				});
		    },
			success:function(xhr){
				process.dialog('close');
				var data;
				if(typeof(xhr)=="object"){
					data=xhr;
				}else{
					data=$.parseJSON(xhr);
				}
				if($.isEmptyObject(data.actionErrors)){
					fileManager.listFile();
					$("#fileUpload").dialog('close');
				}else{
					alert(data.actionErrors.join('<br/>'));
				}
			}
		}); 
	},
	makeDir:function(){
		$("#fileMakeDir [name='root']").val($("#fileManagerSearchList [name='root']").val());
		$.post("fileManagerAction_makeDir.action",$("#fileMakeDir").serialize(),function(data){
			if($.isEmptyObject(data.actionErrors)){
				fileManager.listFile();
				$("#fileMakeDir").dialog('close');
			}else{
				alert(data.actionErrors.join('<br/>'));
			}
		});
	}
};